home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyAssertions.p < prev    next >
Text File  |  1997-03-20  |  1KB  |  72 lines

  1. unit MyAssertions;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types;
  7.  
  8. {$ifc undefined do_debug}
  9. {$setc do_debug := 1}
  10. {$endc}
  11.  
  12. {$ifc not do_debug}
  13. { buggy compiler $ d efinec Assert(b)}
  14. {$definec Assert(b) if false & (b) then begin end else begin end }
  15. {$definec SafeDebugStr(s)}
  16. {$elsec}
  17. {$definec Assert(b) AssertCode(b)}
  18. {$definec SafeDebugStr(b) DebugStr(s)}
  19. {$endc}
  20.  
  21. {$ifc do_debug}
  22.     procedure AssertCode (b: boolean);
  23.     procedure AssertValidPtr (p: univ Ptr);
  24.     procedure AssertValidPtrNil (p: univ Ptr);
  25.     procedure AssertValidHandle (hhhh: univ Handle);
  26.     procedure AssertValidHandleNil (hhhh: univ Handle);
  27. {$endc}
  28.  
  29. implementation
  30.  
  31.     uses
  32.         Memory;
  33.  
  34. {$ifc do_debug}
  35.     procedure AssertCode (b: boolean);
  36.     begin
  37.         if not b then begin
  38.             DebugStr('Assert Failed;sc;hc');
  39.         end;
  40.     end;
  41.  
  42.     procedure AssertValidPtr (p: univ Ptr);
  43.     begin
  44.         Assert((p <> nil) & (not odd(ord4(p))));
  45.     end;
  46.  
  47.     procedure AssertValidPtrNil (p: univ Ptr);
  48.     begin
  49.         if p <> nil then begin
  50.             AssertValidPtr(p);
  51.         end;
  52.     end;
  53.  
  54.     procedure AssertValidHandle (hhhh: univ Handle);
  55.     begin
  56.         AssertValidPtr(hhhh);
  57.         AssertValidPtr(hhhh^);
  58.         Assert(RecoverHandle(hhhh^) = hhhh);
  59.     end;
  60.  
  61.     procedure AssertValidHandleNil (hhhh: univ Handle);
  62.     begin
  63.         if hhhh <> nil then begin
  64.             AssertValidHandle(hhhh);
  65.         end;
  66.     end;
  67. {$endc}
  68.     
  69. end.
  70.  
  71.  
  72.